@isTest
private class SalesOrderHandlerTest {
	/*
		SalesOrderApplicationHandler
		SalesOrderDetailedHandler
	*/
    static testMethod void testMethod1() {
        

        ProductStructure__c ps = new ProductStructure__c();
        ps.Classify3__c = '试剂';
        insert ps;
        Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '试剂';
        p1.ProductStructure__c = ps.Id;
        p1.PriceCompany__c = 'MKSY';
        p1.NCCode__c = '000001';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        
        insert p1; 

         Account acc = TestUtils.createAccount();
        acc.Name = '客户A';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalCustomer','Account');
        insert acc; 

         Account dealer  = TestUtils.createAccount();
        dealer.Name = '经销商A';
        dealer.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerAbroad','Account');
        insert dealer; 


        PriceList__c pl = new PriceList__c();
        pl.Product__c = p1.Id;
        pl.SalesCode__c = '05';
        pl.Price__c = 100;
        pl.Account__c = acc.Id;
        insert pl;

        ReturnSlip__c rs = new ReturnSlip__c();
        rs.Distributor__c = dealer.Id; 
        rs.Status__c = '已批准';
        insert rs;

        SalesOrderApplication__c sa = new SalesOrderApplication__c();
        sa.Buyer__c = acc.Id; 
        sa.ReturnSlip__c = rs.Id; 
        sa.Status__c = '草案中';
        

        sa.PriceExecutionMode__c= '整单折扣';
        insert sa; 
        //System.debug(sa.DiscountRate__c);

        



        SalesOrderDetailed__c ad = new SalesOrderDetailed__c();
        ad.Product__c =p1.Id  ;
        ad.SalesOrderApplication__c = sa.Id ; 
       // ad.DiscountRate__c = 10;
        insert ad;


        sa.Status__c = '已批准';
        update sa;

    }
}